$('#reset').click(function(){
    $('input').val('');
})
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
var pagedatad={};

jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
    var $tab_menu = $(tabBar);
    // 初始化操作
    $tab_menu.removeClass(class_name);
    $(tabBar).eq(i).addClass(class_name);
    $(tabCon).hide();
    $(tabCon).eq(i).show();
    $tab_menu.bind(tabEvent, function () {
        $tab_menu.removeClass(class_name);
        $(this).addClass(class_name);
        var index = $tab_menu.index(this);
        $(tabCon).hide();
        $(tabCon).eq(index).show();
    });
}

$(function () {
    $.Huitab("#tab_goods .tabBar span", "#tab_goods .tabCon", "current", "click", "0")
});
// #tab_demo 父级id
// #tab_demo .tabBar span 控制条
// #tab_demo .tabCon 内容区
// click 事件 点击切换，可以换成mousemove 移动鼠标切换
// 1	默认第2个tab为当前状态（从0开始）

$(function () {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    })
});
var id = sessionStorage.getItem("member_id");
var company_info_id = sessionStorage.getItem("id");
var arr1 = new Array(); //1级分类ID
var arr2 = new Array(); //2级分类ID
var arr3 = new Array(); //3级分类ID
var applcationRange; //适用范围 0:全部分类 1:指定分类 2:指定场景
var arr4 = new Array();//根据二级查询的一级分类ID 数组
var arr5 = new Array();//根据三级查询的二级分类ID 数组

init();
function init() {
    $.ajax({
        /* root.member.getMemberDetailByMemberId*/
        url: root.member.getMemberDetailByMemberId,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            "member_id":id,
            company_info_id:company_info_id,
            "is_exam_page":true
        },
        success: function (data) {
            pagedatad=data;

            if ( data.memberCompanyInfo.exam_status != null &&data.memberCompanyInfo.exam_status == 10  ) {

                $("#exam_time1").css({
                    display: "none"
                });

                $("#adminlogin1").css({
                    display: "none"
                });
                $("#exam_fail_reason1").css({
                    display: "none"
                });
                $("#exam11").css({
                    display: "inline"
                });
                $("#exam22").css({
                    display: "inline"
                });

                $("#create_time1").css({
                    display: "block"
                });

            } else if (data.memberCompanyInfo.exam_status != null &&data.memberCompanyInfo.exam_status == 20 ) {
                $("#exam_time1").css({
                    display: "block"
                });
                $("#adminlogin1").css({
                    display: "block"
                });
                $("#exam_fail_reason1").css({
                    display: "block"
                });


                $("#create_time1").css({
                    display: "block"
                });
                $("#exam11").css({
                    display: "none"
                });
                $("#exam22").css({
                    display: "none"
                });


            } else if (data.memberCompanyInfo.exam_status != null && data.memberCompanyInfo.exam_status == 30 ) {
                $("#exam_time1").css({
                    display: "block"
                });
                $("#adminlogin1").css({
                    display: "block"
                });
                $("#exam_fail_reason1").css({
                    display: "block"
                });


                $("#create_time1").css({
                    display: "block"
                });
                $("#exam11").css({
                    display: "none"
                });
                $("#exam22").css({
                    display: "none"
                });

            }



            //描述

            $('#exam_status').html(data.memberCompanyInfo.exam_status);
            $('#exam_statusid').html(data.memberCompanyInfo.exam_status);
            if(data.memberCompanyInfo.exam_status == 10){
                $('#exam_status').html('待审核');
                //编辑按钮显示
                $("#essentialInformations").css({
                    display: "inline"
                });
                $("#enterprises").css({
                    display: "inline"
                });
            }else if (data.memberCompanyInfo.exam_status == 20) {
                $('#exam_status').html('审核通过');
                //编辑按钮显示
               /* $("#essentialInformations").css({
                    display: "none"
                }); $("#enterprises").css({
                    display: "none"
                });*/
                $("#essentialInformations").css({
                    display: "inline"
                });
                $("#enterprises").css({
                    display: "inline"
                });


            }else if (data.memberCompanyInfo.exam_status == 30) {
                $('#exam_status').html('审核失败');
                //编辑按钮显示
                $("#essentialInformations").css({
                    display: "none"
                }); $("#enterprises").css({
                    display: "none"
                });
            }
            /*$("#exam11").replaceWith("<div class=\"btn radius size-S mr-10 exam1\" id='"+data.memberCompanyInfo.member_id+"' onclick='refuse("+data.memberCompanyInfo.member_id+")' >拒绝</div>")
            $("#exam22").replaceWith("<div class=\"btn radius size-S mr-10 exam2\" id='"+data.memberCompanyInfo.member_id+"' onclick='Determine("+data.memberCompanyInfo.member_id+")' >通过</div>")
*/
            $("#exam11").attr("onclick", 'refuse("' + data.memberCompanyInfo.member_id + '")');
            $("#exam22").attr("onclick", 'Determine("' + data.memberCompanyInfo.member_id + '")');
            $('#create_time').html(data.memberCompanyInfo.create_time);
            $('#exam_time').html(data.memberCompanyInfo.exam_time);
            $('#adminlogin').html(data.memberCompanyInfo.exam_username);
            $('#exam_fail_reason').html(data.memberCompanyInfo.exam_fail_reason);
            $('#login_account').html(data.memberInfo.login_account);
            $('#mobile_phone').html(data.memberInfo.mobile_phone);
            $('#registerPlatform').html(data.memberInfo.register_platform);
            if(data.memberInfo.register_platform == 10){
                $('#registerPlatform').html('PC');
            }else if (data.memberInfo.register_platform == 20) {
                $('#registerPlatform').html('Android');

            }else if (data.memberInfo.register_platform == 30) {
                $('#registerPlatform').html('IOS');

            }else if (data.memberInfo.register_platform == 40) {
                $('#registerPlatform').html('H5');

            }else if (data.memberInfo.register_platform == 50) {
                $('#registerPlatform').html('云采后台');

            }else if (data.memberInfo.register_platform == 60) {
                $('#registerPlatform').html('小程序端');

            }else if (data.memberInfo.register_platform == 0) {
                $('#registerPlatform').html('');

            }
            $('#register_time').html(data.memberInfo.register_time);
            $('#status').html(data.memberInfo.status);
            if(data.memberInfo.status == 10){
                $('#status').html('开启');
            }else if (data.memberInfo.status == 20) {
                $('#status').html('关闭');

            }
            $('#email').html(data.memberCompanyInfo.email);

            $('#company_name').html(data.memberCompanyInfo.company_name);
            $('#addressOfCompany').html(data.memberCompanyInfo.locate_province_name+data.memberCompanyInfo.locate_city_name+data.memberCompanyInfo.locate_area_name+data.memberCompanyInfo.locate_street_name);
            $('#detail_address').html(data.memberCompanyInfo.detail_address);
            $('#business_type').html(data.memberCompanyInfo.business_type);
            if(data.memberCompanyInfo.business_type == 10){
                $('#business_type').html('工程');
            }else if (data.memberCompanyInfo.business_type == 20) {
                $('#business_type').html('工矿');

            }else if (data.memberCompanyInfo.business_type == 30) {
                $('#business_type').html('商店');

            }else if (data.memberCompanyInfo.business_type == 40) {
                $('#business_type').html('外贸');

            }else if (data.memberCompanyInfo.business_type == 50) {
                $('#business_type').html('物业');

            }else if (data.memberCompanyInfo.business_type == 60) {
                $('#business_type').html('其他');

            }else if (data.memberCompanyInfo.business_type == 0) {
                $('#business_type').html('');

            }
            $('#business_license_num').html(data.memberCompanyInfo.business_license_num);
            $('#licence').html("<img onclick=picShow('查看图片','../../html/goods/picShow.html','"+data.memberCompanyInfo.licence_pic_path+"','500','300','110') height='30' src='"+data.memberCompanyInfo.licence_pic_path+"'>");

            getMemberBelonging(data.memberInfo.pushman_company_id);
            if(data.memberCompanyInfo.exam_status == 10)
            {
                $("#pushmanCompanyId").removeAttr("disabled");
                $("#pushmanCompanySave").show();
            }
        },
        error: function () {
            $.Huimodalalert('失败！');
        }
    });

    
}

//拒绝按钮
var index=0;
function refuse(id,name) {
    var popEle = $('#chuliPop');
    var target = document.getElementById(''+id+'');
    /* var common = target.parentElement.parentElement.previousElementSibling.lastElementChild.lastElementChild.innerHTML*/

    var cu = layer.confirm('<textarea id="remarks" style="width:200px;height:100px;resize: none;" maxlength="60" placeholder="请填写审核未通过原因（客户可见请规范填写）" ></textarea>', {title:'提示',btn: ['确认', '取消']}, function(index){
        finish3(id,cu,name)
        var inv = $("#remarks").val();
        layer.close(cu);
    },function(){
        layer.close(cu);

    });
    /*$("#remarks").val(common)*/
}
//第二个
function finish3(id,val){
    var loginacounts = sessionStorage.getItem("loginacounts");
    var target = document.getElementById(''+id+'');
    var remarks = $("#remarks").val();
    console.log(remarks)
    console.log(id)
    var reason=$('#reason'+id+'').val();
    if(reason!=''){
        $.ajax({
            url: root.member.updateMemberCompanyExamStatus,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "id":company_info_id,
                "member_id":id,
                "exam_fail_reason":remarks,
                "exam_status":30,
                "exam_userid":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                "exam_username":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "loginAccount":loginacounts
            }),
            success: function (data) {
                init();
                target.onclick = null;
                target.setAttribute("onclick", 'editor('+id+')')

            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })}
    else{
        $.Huimodalalert('处理结果不能为空！',2000);
    };
    layer.close(index);
}


//图片放大
function picShow(title, url, imgUrl) {
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
    sessionStorage.setItem("imgUrl", imgUrl);
    layer_show(title, url, "800", "500");
}
var caozuoapp=0
var Pics=""
//图片上传
function addBtn(cen) {
    $(cen).prev().trigger('click');
}
var formData = new FormData();
// 提交上传图片
function getupfilerul(can,e){
    var formData = new FormData();
    formData.append('file',$(can)[0].files[0]);
    // formData.append('file',$("#fileUp").files);
    console.log($(can)[0].files[0])
    console.log(formData)
    $.ajax({
        url: root.inter.imgUpload,
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData : false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType : false,
        data: formData,
        success: function (data) {
            for(var i=0; i<data.length; i++){
                $(can).prev().val(data[0].reletivePath)
                $(can).prev().text(data[0].reletivePath)
            }
            caozuoapp=1
            Pics=data[0].fullPath
            $("#deletapic1").css({
                display: "inline"
            });

        }
    })
}
// 上传图片返现
function putDataToPage(e,can) {
    //验证
    verificationPicFileType(can)
    verificationPicFileSize(can)
    for(var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if(!(/^image\/.*$/i.test(file.type))) {
            continue; //不是图片 就跳出这一次循环
        }
        //实例化FileReader API
        var freader = new FileReader();
        freader.readAsDataURL(file);
        freader.onload = function (e) {
            var data = e.target.result;
            //加载图片获取图片真实宽度和高度
            var img = new Image();
            img.src= data;
            img.onload = function(){

                    $(can).parent().prev().children().attr("src", e.target.result);
                $(can).parent().prev().children().attr("onclick", "picShow('查看图片','../../html/goods/picShow.html','"+e.target.result+"','500','300','110')");

                /* $(can).next().text('更换图片')*/
                    getupfilerul(can,e)

            };


        }
    }
    formData.append('file', $(can)[0].files[0]);
}
// 图片类型验证
function verificationPicFileType(file) {
    var flag=false;
    var fileTypes = [".jpg", ".png",".jpeg",".bmp"];
    var filePath = file.value;
    //当括号里面的值为0、空字符、false 、null 、undefined的时候就相当于false
    if(filePath){
        var isNext = false;
        var fileEnd = filePath.substring(filePath.indexOf("."));
        for (var i = 0; i < fileTypes.length; i++) {
            if (fileTypes[i] == fileEnd) {
                isNext = true;
                flag= true;
                break;
            }
        }
        if (!isNext){
            $.Huimodalalert('您上传的图片格式错误',2000);
            file.value = "";
            flag=false;
        }
    }
    return flag;
}
//图片大小验证
function verificationPicFileSize(file) {
    var flag=false;
    var fileSize = 0;
    var fileMaxSize = Number(1024);
    var filePath = file.value;
    if(filePath){
        fileSize =file.files[0].size;
        var size = fileSize / Number(1024);
        if (size > 5 * 1024 * 1024) {
            $.Huimodalalert('您上传的图片格式错误',2000);
            file.value = "";
            flag=false;
        }else{
            flag=true;
        }
    }
    return flag;
}
//客户基本信息更改
function essentialInformation() {
    $("#essentialInformation").modal("show");
    $.ajax({
        /* root.member.getMemberDetailByMemberId*/
        url: root.member.getMemberDetailByMemberId,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            "member_id":id,
            company_info_id:company_info_id,
            "is_exam_page":true
        },

        success: function (data) {
            $("#loginaccount").html(data.memberInfo.login_account);
            $("#mobilephone").html(data.memberInfo.mobile_phone);


            if(data.memberInfo.register_platform == 10){
                $('#register_Platform').html('PC');
            }else if (data.memberInfo.register_platform == 20) {
                $('#register_Platform').html('Android');

            }else if (data.memberInfo.register_platform == 30) {
                $('#register_Platform').html('IOS');

            }else if (data.memberInfo.register_platform == 40) {
                $('#register_Platform').html('H5');

            }else if (data.memberInfo.register_platform == 60) {
                $('#register_Platform').html('小程序端');
                
            }else if (data.memberInfo.register_platform == 0) {
                $('#register_Platform').html('');

            }
            $("#registertime").html(data.memberInfo.register_time);
            if(data.memberInfo.status == 10){
                $('#status2').html('开启');
            }else if (data.memberInfo.status == 20) {
                $('#status2').html('关闭');

            }
            $("#businessman").val(data.memberCompanyInfo.business_man);
            $("#businessphone").val(data.memberCompanyInfo.business_phone);
            if(data.memberCompanyInfo.email!=null){
                $("#email2").val(data.memberCompanyInfo.email);
            }else {
                $("#email2").val("");
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//保存客户基本信息更改
function addessentialInformation() {
    $.ajax({
        url: root.member.updateMemberByCertification,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "member_id":id,
            "company_info_id":company_info_id,
            "business_man":$("#businessman").val(),
            "business_phone":$("#businessphone").val(),
            "email":$("#email2").val(),
        }),

        success: function (data) {
            if(data.errorCode==0){
                $.Huimodalalert('编辑成功',2000);
                $("#essentialInformation").modal("hide");
                init()
            }else {
                $.Huimodalalert(data.msg,2000);
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//取消
function essentialInformationclose() {
    $("#essentialInformation").modal("hide");
}
var originAddress = true;
var membershipdata=""
//企业信息更改
function enterprise() {
    $("#enterprise").modal("show");
    $.ajax({
        /* root.member.getMemberDetailByMemberId*/
        url: root.member.getMemberDetailByMemberId,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            "member_id":id,
            company_info_id:company_info_id,
            "is_exam_page":true
        },

        success: function (data) {
            membershipdata=data
            queryAddress("pin_list0")
            $("#companyname1").val(data.memberCompanyInfo.company_name);
            $("#mobilephone").val(data.memberCompanyInfo.mobile_phone);
            $("#detailaddress1").val(data.memberCompanyInfo.detail_address);
            $("#businesstype1").val(data.memberCompanyInfo.business_type);
            $("#businesslicensenum").val(data.memberCompanyInfo.business_license_num);
            $("#licenc").attr("src", data.memberCompanyInfo.licence_pic_path);
            $("#licenc").attr("onclick", "picShow('查看图片','../../html/goods/picShow.html','"+data.memberCompanyInfo.licence_pic_path+"','500','300','110')");


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//企业信息取消
function enterpriseclose() {
    $("#enterprise").modal("hide");
    if($('#addressOfCompany').html()!=""){
        $("#pin_list1").html("")
        $("#pin_list2").html("")
        $("#pin_list3").html("")
        $("#pin_list4").html("")
    }


}
//地址
function queryAddress(targetId) {
    var parentCode = ""; // 上级地址ID
    var nextTarget = ""; // 下级下拉列表ID
    var selectedOption = ""; // 选中项
    var pleaseChoose=""//请选择
    $("#pin_lists1").attr("disabled","disabled")
    $("#pin_lists2").attr("disabled","disabled")
    $("#pin_lists3").attr("disabled","disabled")
    $("#pin_lists4").attr("disabled","disabled")
    if ("pin_list0" == targetId) { // 省
        parentCode = "";
        nextTarget = "pin_list1";
        pleaseChoose="pin_lists1"
        if (originAddress == true) {
            console.log(membershipdata)
            selectedOption = membershipdata.memberCompanyInfo.locate_province_code
        } else {
            selectedOption = $("#pin_list1").val();
        }
    } else if ("pin_list1" == targetId) { // 市
        if($("#pin_list1").val()!=null){
            parentCode = $("#pin_list1").val();
        }else {
            parentCode ="00"
        }
        nextTarget = "pin_list2";
        pleaseChoose="pin_lists2"
        if (originAddress == true) {
            selectedOption = membershipdata.memberCompanyInfo.locate_city_code
        } else {
            selectedOption = $("#pin_list2").val();
        }
    } else if ("pin_list2" == targetId) { // 县区
        if($("#pin_list2").val()!=null){
            parentCode = $("#pin_list2").val();
        }else {
            parentCode = "00";
        }

        nextTarget = "pin_list3";
        pleaseChoose="pin_lists3"
        if (originAddress == true) {
            selectedOption = membershipdata.memberCompanyInfo.locate_area_code
        } else {
            selectedOption = $("#pin_list3").val();
        }
    } else if ("pin_list3" == targetId) { // 城镇
        if($("#pin_list3").val()!=null){
            parentCode = $("#pin_list3").val();
        }else {
            parentCode = "00"
        }
        nextTarget = "pin_list4";
        pleaseChoose="pin_lists4"
        if (originAddress == true) {
            selectedOption = membershipdata.memberCompanyInfo.locate_street_code
        } else {
            selectedOption = $("#pin_list4").val();
        }
    }
    var user_data = {
        parentCode: parentCode
    };
    var succCallBack = function (data, status, response) {
        if (data.errorCode == "0") {
            var addressList = data.list;
            if (addressList == '') {
                var cer = '<option value="" id='+pleaseChoose+'>请选择</option>';
                $("#" + nextTarget).html(cer);
            } else {
                var cer = '<option value="" id='+pleaseChoose+'>请选择</option>';
                for (var i = 0; i < addressList.length; i++) {
                    if(selectedOption == addressList[i].code){
                        cer += '<option value="' + addressList[i].code + '" selected>' + addressList[i].name + '</option>'
                    }else {
                        cer += '<option value="' + addressList[i].code + '">' + addressList[i].name + '</option>'
                    }

                }
                $("#" + nextTarget).html(cer);
            }

        }
        // 查询子级地址信息
        if(nextTarget != "pin_list4"){
            queryAddress(nextTarget);
        }else {
            $("#pin_lists4").attr("disabled","disabled")
        }

    };
    web.doAjax(root.orderInter.order_return_address_new, 'post', user_data, succCallBack);
    if (targetId == "pin_list1") {
        $("#" + targetId + " option").each(function(){//遍历所有option
            var text = $(this).text();
            var select = $(this).select();
            console.log(select[0].selected);
            if(select[0].selected){
                if (text == "北京" || text == "上海" || text == "天津" || text == "重庆" || text == "台湾" || text == "香港" || text == "澳门" || text == "钓鱼岛"|| text == "海南") {
                    $("#pin_list4").hide();
                } else {
                    $("#pin_list4").show();
                }

            }

        });
    }
}


//限制字符
var len
var Preser
var common=20//要限制输入的字数
var common2=50//要限制输入的字数
$('#commonText').text('('+common+')')
function checkMaxIut(me,val) {
    var text=$(me).val()
    strlen(text)
    if(val==1){
        if(len>common){
            $(me).val(Preser)
        }else {
            Preser=$(me).val()
        }
    }else {
        if(len>common2){
            $(me).val(Preser)
        }else {
            Preser=$(me).val()
        }
    }

}
function strlen(str){
    len = 0;
    for (var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            len++;
        } else {
            len+=2;
        }
    }
    $('#textSpan').text((len>40)?40:len)
    return len;
}
//企业信息保存
function enterpriseadd() {
    if($("#companyname1").val().trim()==""){
        $.Huimodalalert('请填写公司名称',2000);
        return false;
    }
    if($("#businesslicensenum").val()==""){
        $.Huimodalalert('请填写营业执照注册号',2000);
        return false;
    }
    if($("#licenc").attr("src")==""){
        $.Huimodalalert('请上传营业执照',2000);
        return false;
    }
    var licence_pic_path=""
    if(caozuoapp==1){
        //操作选中图片是=时
        licence_pic_path=Pics
    }else {
        licence_pic_path=$("#licenc").attr("src")
    }
 //省
    var locate_province_names=""
    var locate_province_codes=""
    if($("#pin_list1").val()==null){
        locate_province_names=""
        locate_province_codes=""
    }else {
        locate_province_names=$("#pin_list1 option:selected").text()
        locate_province_codes=$("#pin_list1").val()
    }

//市
    var locate_city_names=""
    var locate_city_codes=""
    if($("#pin_list2").val()==null){
        locate_city_names=""
        locate_city_codes=""
    }else {
        locate_city_names=$("#pin_list2 option:selected").text()
        locate_city_codes=$("#pin_list2").val()
    }

//区
    var locate_area_names=""
    var locate_area_codes=""
    if($("#pin_list3").val()==null){
        locate_area_names=""
        locate_area_codes=""
    }else {
        locate_area_codes=$("#pin_list3").val()
        locate_area_names=$("#pin_list3 option:selected").text()
    }
 //街道
    var locate_street_names=""
    var locate_street_codes=""
    if($("#pin_list4").val()==null){
        locate_street_names=""
        locate_street_codes=""
    }else {
        locate_street_codes=$("#pin_list4").val()
        locate_street_names=$("#pin_list4 option:selected").text()
    }
    if($("#pin_list1").val()!=null){

        if (locate_province_names == "北京" || locate_province_names == "上海" || locate_province_names == "天津" || locate_province_names == "重庆" || locate_province_names == "台湾" || locate_province_names == "香港" || locate_province_names == "澳门" || locate_province_names == "钓鱼岛"|| locate_province_names == "海南") {
           if($("#pin_list2").val()==null||$("#pin_list3").val()==null){
               $.Huimodalalert('请完善公司所在地',2000);
               return false;
           }
        } else {
            if($("#pin_list2").val()==null||$("#pin_list3").val()==null){
                $.Huimodalalert('请完善公司所在地',2000);
                return false;
            }
            if($("#pin_list4").val()==null){
                if($("#pin_list4").children().length>1){
                    $.Huimodalalert('请完善公司所在地',2000);
                    return false;
                }
            }

        }
    }

    $.ajax({
        url: root.member.updateMemberCompanyInfoByCertification,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "member_id":id,
            "id":company_info_id,
            locate_province_code: locate_province_codes,
            locate_province_name: locate_province_names,
            locate_city_code:locate_city_codes,
            locate_city_name:locate_city_names,
            locate_area_code:locate_area_codes,
            locate_area_name:locate_area_names,
            locate_street_code:locate_street_codes,
            locate_street_name:locate_street_names,
            company_name:$("#companyname1").val().trim(),
            detail_address:$("#detailaddress1").val().trim(),
            business_type:$("#businesstype1").val(),
            business_license_num:$("#businesslicensenum").val(),
            licence_pic_path:licence_pic_path,
        }),

        success: function (data) {
            if(data.errorCode==0){
                $.Huimodalalert('编辑成功',2000);
                $("#enterprise").modal("hide");
                init()
            }else {
                $.Huimodalalert(data.msg,2000);
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//通过按钮
function Determine() {
    $("#crmCustomer").modal("show")
}
//匹配客户
function matchCustomers(val) {
    if(val==1){
       /* 系统匹配客户*/
        $("#system").attr("style","color: #fff;background-color: #4A90E2;border-color: #4A90E2;")
        $("#artificial").removeAttr("style")
        /*隐藏模块*/
        $("#searchCriteria").css({
            display: "none"
        })
        $("#customerInformation").css({
            display: "none"
        })
        $("#matchFailed").css({
            display: "none"
        })
        $("#bindingCustomers").css({
            display: "none"
        })
        $("#createacustomer").css({
            display: "none"
        })
        /*展示模块*/
        $("#matchings").css({
            display: "block"
        })
    }else if(val==2){
        /* 人工匹配客户*/
        $("#artificial").attr("style","color: #fff;background-color: #4A90E2;border-color: #4A90E2;")
        $("#system").removeAttr("style")
        /*隐藏模块*/
        $("#matchings").css({
            display: "none"
        })
        $("#customerInformation").css({
            display: "none"
        })
        $("#matchFailed").css({
            display: "none"
        })
        $("#bindingCustomers").css({
            display: "none"
        })
        $("#createacustomer").css({
            display: "none"
        })
        /*展示模块*/
        $("#searchCriteria").css({
            display: "block"
        })
    }else if(val==3){
        /*自动匹配客户*/
        $.ajax({
            url: root.member.queryCRMCustomerList,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "companyName":$("#company_name").html(),
                "mobile":$("#mobile_phone").html()
            }),
            success: function (data) {
                if(data.errorCode==0){
                    var informations=data.data
                    if(informations.length!=0){
                        /*隐藏模块*/
                        $("#searchCriteria").css({
                            display: "none"
                        })
                        $("#matchings").css({
                            display: "none"
                        })

                        $("#matchFailed").css({
                            display: "none"
                        })
                        $("#bindingCustomers").css({
                            display: "none"
                        })
                        $("#createacustomer").css({
                            display: "none"
                        })
                        /*展示模块*/
                        $("#customerInformation").css({
                            display: "block"
                        })
                        $("#bindingCustomers").css({
                            display: "block"
                        })
                        var crmdatas=''
                        for (var i=0;i<informations.length;i++){
                            var isForbbiden=''
                            if(informations[i].isForbbiden==0){
                                isForbbiden='启用'
                            }else if(informations[i].isForbbiden==1){
                                isForbbiden='禁用'
                            }
                            var matchedType=""
                            for (var k=0;k<informations[i].matchedType.length;k++) {
                                if (informations[i].matchedType[k]==1) {
                                    matchedType+='&nbsp;名称相同'
                                }else if (informations[i].matchedType[k]==2) {
                                    matchedType+='&nbsp;名称近似'
                                }else if (informations[i].matchedType[k]==3) {
                                    matchedType+='&nbsp;手机号相同'
                                }
                            }

                            crmdatas+='<div class="crm_radio">\n' +
                                '                            <div class="clearfix">\n' +
                                '                                <input type="radio" value="'+informations[i].customerCode+'" data-id="'+informations[i].customerType+'" data-name="'+informations[i].customerName+'"  name="memberInformationCode">匹配原因：<span>'+matchedType+'</span>\n' +
                                '                            </div >\n' +
                                '                            <div class="clearfix list">\n' +
                                '                                <div class="company">'+informations[i].customerName+'<div class="level">'+informations[i].customerLevel+'</div></div>\n' +
                                '                                <ul class="crm_customerinfo clearfix">\n' +
                                '                                    <li><label >客户代码:</label><span class="radius ml-10 ">'+informations[i].customerCode+'</span></li>\n' +
                                '                                    <li><label >状态:</label><span class="radius ml-10 ">'+isForbbiden+'</span></li>\n' +
                                '                                    <li><label >客户联系人:</label><span class="radius ml-10 ">'+informations[i].contacts+'</span></li>\n' +
                                '                                    <li><label >联系电话:</label><span class="radius ml-10 ">'+informations[i].telNo1+'</span></li>\n' +
                                '                                    <li><label >客户归属:</label><span class="radius ml-10 ">'+informations[i].customerGroupName+'</span></li>\n' +
                                '                                    <li><label >销售主管:</label><span class="radius ml-10 ">'+informations[i].salesMan+'</span></li>\n' +
                                '                                </ul>\n' +
                                '                            </div>\n' +
                                '                        </div>';


                        }
                        $("#customerInformation").html(crmdatas)

                    }else {
                        $("#matchFailed").css({
                            display: "block"
                        })
                        $("#createacustomer").css({
                            display: "block"
                        })

                        $("#searchCriteria").css({
                            display: "none"
                        })
                        $("#matchings").css({
                            display: "none"
                        })
                        $("#bindingCustomers").css({
                            display: "none"
                        })
                        $("#customerInformation").css({
                            display: "none"
                        })

                    }
                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        });

    }else if(val==4){
        /*人工匹配搜索*/
        if($("#customerCode").val()==""&&$("#customerName").val()==""&&$("#mobile").val()==""){
            $.Huimodalalert('请至少填写一项查询',2000);
            return false
        }
        $.ajax({
            url: root.member.queryYCCustomerList,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "customerCode":$("#customerCode").val(),
                "customerName":$("#customerName").val(),
                "mobile":$("#mobile").val()

            }),
            success: function (data) {
                if(data.errorCode==0){
                    var informations=data.data
                    if(informations.length!=0){
                        /*隐藏模块*/

                        $("#matchings").css({
                            display: "none"
                        })

                        $("#matchFailed").css({
                            display: "none"
                        })

                        $("#createacustomer").css({
                            display: "none"
                        })

                        /*展示模块*/
                        $("#customerInformation").css({
                            display: "block"
                        })
                        $("#searchCriteria").css({
                            display: "block"
                        })
                        $("#bindingCustomers").css({
                            display: "block"
                        })
                        var crmdatas=''
                        for (var i=0;i<informations.length;i++){
                            var isForbbiden=''
                            if(informations[i].isForbbiden==0){
                                isForbbiden='启用'
                            }else if(informations[i].isForbbiden==1){
                                isForbbiden='禁用'
                            }
                            crmdatas+='<div class="crm_radio">\n' +
                                '                            <div class="clearfix">\n' +
                                '                                <input type="radio" value="'+informations[i].customerCode+'" name="memberInformationCode">' +
                                '                            </div >\n' +
                                '                            <div class="clearfix list">\n' +
                                '                                <div class="company">'+informations[i].customerName+'<div class="level">'+informations[i].customerLevel+'</div></div>\n' +
                                '                                <ul class="crm_customerinfo clearfix">\n' +
                                '                                    <li><label >客户代码:</label><span class="radius ml-10 ">'+informations[i].customerCode+'</span></li>\n' +
                                '                                    <li><label >状态:</label><span class="radius ml-10 ">'+isForbbiden+'</span></li>\n' +
                                '                                    <li><label >客户联系人:</label><span class="radius ml-10 ">'+informations[i].contacts+'</span></li>\n' +
                                '                                    <li><label >联系电话:</label><span class="radius ml-10 ">'+informations[i].telNo1+'</span></li>\n' +
                                '                                    <li><label >客户归属:</label><span class="radius ml-10 ">'+informations[i].customerGroupName+'</span></li>\n' +
                                '                                    <li><label >销售主管:</label><span class="radius ml-10 ">'+informations[i].salesMan+'</span></li>\n' +
                                '                                </ul>\n' +
                                '                            </div>\n' +
                                '                        </div>';


                        }
                        $("#customerInformation").html(crmdatas)

                    }else {
                        $("#matchFailed").css({
                            display: "block"
                        })
                        $("#createacustomer").css({
                            display: "block"
                        })
                        $("#searchCriteria").css({
                            display: "block"
                        })
                        $("#matchings").css({
                            display: "none"
                        })
                        $("#bindingCustomers").css({
                            display: "none"
                        })
                        $("#customerInformation").css({
                            display: "none"
                        })

                    }
                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        });
    }
}
//创建客户
function CreatingCustomer() {
    $("#CreatingCustomer").modal("show")
    $.ajax({
        url: root.member.addCRMCustomer,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "memberId":id,
        }),
        success: function (data) {
            if(data.errorCode==0){
                $("#CreatingCustomer").modal("hide")
                $("#establishCustomer").modal("show")
                $("#success").css({
                    display: "block"
                })
                $("#fail").css({
                    display: "none"
                })
                $("#msgall1").html(data.msg)
            }else {
                $("#CreatingCustomer").modal("hide")
                $("#establishCustomer").modal("show")
                $("#success").css({
                    display: "none"
                })
                $("#fail").css({
                    display: "block"
                })
                $("#msgall").html(data.msg)
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//重新创建CRM客户
function CreatingCustomer2() {
    $("#establishCustomer").modal("hide")
    CreatingCustomer()
}
//按钮返回CRM
function buttonBack() {
    $("#establishCustomer").modal("hide")
    $("#crmCustomer").modal("show")
    matchCustomers(1)
}
//确认绑定
function submitCompanyMemberbindCustomer() {
    $.ajax({
        url: root.member.submitCompanyMemberbindCustomer,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "customerCode":$("input:radio[name='memberInformationCode']:checked").val(),
            "member_id":id,
            "id":company_info_id,
            "exam_status":20,
            "customerType":$("input:radio[name='memberInformationCode']:checked").attr("data-id"),
            "company_name":$("input:radio[name='memberInformationCode']:checked").attr("data-name"),
            "exam_userid":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "exam_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name
        }),
        success: function (data) {
            if(data.errorCode==0){
                $.Huimodalalert('绑定成功',2000);
                $("#crmCustomer").modal("hide")
                init();
            }else {
                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

//获取会员归属
function getMemberBelonging (push_man_companyId) {
    console.log("获取会员归属");
    $.ajax({
        url: root.inter.getGroup,
        type: "post",
        async: false,
        data:{ organizationIds : sessionStorage.getItem("companya")},
        success: function (res) {
            if (res.errorCode == 0) {
                var data = "";
                $.each(res.group,function(id,obj){
                    if (obj.id == push_man_companyId) {
                        data += "<option value=\"" + obj.id + "\" selected>" + obj.organization_name + "</option>";
                    }else{
                        data += "<option value=\"" + obj.id + "\">" + obj.organization_name + "</option>";
                    }
                })
                $("#pushmanCompanyId").append(data);
            } else {
                $.Huimodalalert(res.errorMessage,2000);
            }
        },
        complete: function () { },
        error: function () { },
    });
}

//修改会员归属
function saveMemberBelonging(){
    var param ={
        member_id:sessionStorage.getItem("member_id"),
        companyId:$("#pushmanCompanyId").val(),
        company_name:$("#pushmanCompanyId option:selected").text()
    };
    $.ajax({
        url: root.member.modifyMemberCompanyId,
        type: "post",
        async: false,
        contentType: "application/json",
        data:JSON.stringify(param),
        success: function (res) {
            if (res.errorCode == 0) {
                var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >修改成功</span>', {title:'提示',btn: ['确定']}, function(index){        
                    layer.close(curInd);
                    window.parent.searchLists();
                    parent.layer.closeAll();
                });
            }else{
                $.Huimodalalert(res.msg,2000);
            }
        },
        complete: function () { },
        error: function () { },
    });
}